package com.tungse.study.single;
/**
 * 枚举类型是饿汉式单例
 * 但是枚举实现的单例可以防止反射破坏
 */
public enum EnumSingle {

    INSTANCE;
    public EnumSingle getInstance(){
        return INSTANCE;
    }

    //实现一些方法
    public String someMethod(String str) {
        return str.toUpperCase();
    }

    public void test(){
        System.out.println("test");
    }
}


class Test{

    public static void main(String[] args) {
        EnumSingle instance = EnumSingle.INSTANCE;
        EnumSingle instance1 = EnumSingle.INSTANCE;
        System.out.println(instance == instance1);


        System.out.print(instance.someMethod("hello "));
        System.out.println(instance1.someMethod("world"));

        instance.test();
        instance1.test();
    }

}